/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.zr.coverflow.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Text;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import com.futuremind.recyclerviewfastscroll.Utils;

import java.util.ArrayList;
import java.util.List;

import me.crosswall.coverflow.demo.ResourceTable;
import me.crosswall.lib.coverflow.ListContainerView;
import me.crosswall.lib.coverflow.MyPageSliderProvider;
import me.crosswall.lib.coverflow.PageSliderAdapter;
import me.crosswall.lib.coverflow.view.PagerContainer;

/**
 * Utils
 *
 * @since 2021-03-24
 */
public class ListContainerAbilitySlice extends AbilitySlice {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x2021, "ListContainerAbilitySlice");
    private Text listTextView;
    private Text testview;
    private DependentLayout deidlyaout;
    private PagerContainer listcontainerpageslider2;
    private PagerContainer pageSlidertestpageslider;
    private List arrayList = null;
    private List protectlist = null;
    private boolean isAlan=false;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_listcontainer_view);
        addData();
        initview();
        initdata();
    }

    private void initview() {
        pageSlidertestpageslider = (PagerContainer) findComponentById(ResourceTable.Id_listcontainerpageslider);
        listcontainerpageslider2 = (PagerContainer) findComponentById(ResourceTable.Id_listcontainerpageslider2);
        listTextView = (Text) findComponentById(ResourceTable.Id_listTextView);
        testview = (Text) findComponentById(ResourceTable.Id_testview);
        deidlyaout = (DependentLayout) findComponentById(ResourceTable.Id_Deid);
        Utils.setDependentLayout(deidlyaout);
        Utils.setTextview(testview);
    }

    private void initdata() {
        MyPageSliderProvider pageSliderListContainer = new MyPageSliderProvider(this, arrayList);
        PageSliderAdapter bannerAdapter1 = new PageSliderAdapter((ArrayList<Integer>) protectlist, getContext());
        pageSlidertestpageslider.setPageadapter(bannerAdapter1);
        listcontainerpageslider2.setPageadapter(pageSliderListContainer);
        PagerContainer.PageItemClickListener onSelectListener1 = new PagerContainer.PageItemClickListener() {
            @Override
            public void onItemClick(int index) {
               listTextView.setText("Item" + index);
                isAlan=true;
            }

            @Override
            public void onPageSliding(int position, float positionOffset, int positionOffsetPixels) {
             }
        };
        pageSlidertestpageslider.setPageItemClickListener(onSelectListener1);

        PagerContainer.PageItemClickListener onSelectListener2 = new PagerContainer.PageItemClickListener() {
            @Override
            public void onItemClick(int index) {
                listTextView.setText("Item" + index);
                pageSlidertestpageslider.setCurrpage(index);
                isAlan=true;
            }
            @Override
            public void onPageSliding(int position, float positionOffset, int positionOffsetPixels) {
              }
        };
        listcontainerpageslider2.setPageItemClickListener(onSelectListener2);
    }

    private void addData() {
        arrayList = new ArrayList<Component>();
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));

        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));

        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));
        arrayList.add(new ListContainerView(this));

        protectlist = new ArrayList<Integer>();

        protectlist.add(ResourceTable.Media_color_0);
        protectlist.add(ResourceTable.Media_harcolor1);
        protectlist.add(ResourceTable.Media_harcolor2);
        protectlist.add(ResourceTable.Media_harcolor3);
        protectlist.add(ResourceTable.Media_harcolor4);
        protectlist.add(ResourceTable.Media_harcolor5);
        protectlist.add(ResourceTable.Media_harcolor6);
        protectlist.add(ResourceTable.Media_harcolor7);
        protectlist.add(ResourceTable.Media_harcolor8);
        protectlist.add(ResourceTable.Media_harcolor9);
        protectlist.add(ResourceTable.Media_harcolor10);
        protectlist.add(ResourceTable.Media_harcolor11);
        protectlist.add(ResourceTable.Media_harcolor12);
        protectlist.add(ResourceTable.Media_harcolor13);
        protectlist.add(ResourceTable.Media_harcolor14);
    }
}
